﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MLSharp.Classification;

namespace MLSharp.SubgroupDiscovery
{
	/// <summary>
	/// Simple factory that returns <see cref="SDAlgorithm"/> instances.
	/// </summary>
	/// <remarks>
	/// Though this implements the IClassifierFactory interface,
	/// it doesn't build true classifiers.  The returned SDAlgorithm
	/// instances perform the SD algorithm (as defined in "Expert-Guided
	/// Subgroup Discovery: Methodology and Appliaction") on demand.
	/// </remarks>
	public class SDAlgorithmFactory : IClassifierFactory
	{
		#region Private Fields

		/// <summary>
		/// The options.
		/// </summary>
		private readonly SDOptions mOptions = new SDOptions();

		#endregion

		#region Public Properties

		///<summary>
		/// The options to use when constructing SDAlgorithm instances.
		///</summary>
		public SDOptions Options
		{
			get
			{
				return mOptions;
			}
		}

		#endregion

		#region Implementation of IClassifierFactory

		/// <summary>
		/// Builds a classifier to predict the specified attribute using the 
		/// specified training data.
		/// </summary>
		/// <param name="trainingData">The training data.</param>
		/// <returns>A classifier.</returns>
		IClassifier IClassifierFactory.BuildClassifier(IDataSet trainingData)
		{
			return GetSDAlgorithm();
		}

		/// <summary>
		/// The options object for the factory.
		/// </summary>
		/// <remarks>
		/// Implementors should implement this property explicitly and expose 
		/// a strongly-typed options object instead.  
		/// </remarks>
		object IClassifierFactory.Options
		{
			get { return Options; }
		}

		#endregion

		#region Public Methods

		/// <summary>
		/// Gets an instance of the SD algorithm.
		/// </summary>
		/// <returns></returns>
		public SDAlgorithm GetSDAlgorithm()
		{
			return new SDAlgorithm(mOptions);
		}

		#endregion
	}
}
